﻿using System.Collections.Generic;
using Koonsoft.HYCRM.DAL;

namespace Koonsoft.HYCRM.BLL
{
    public class DelegateRoleBLL
    {
        private DelegateRoleDAL _dal = null;

        protected DelegateRoleDAL DAL
        {
            get
            {
                if (_dal == null)
                {
                    _dal = new DelegateRoleDAL();
                }

                return _dal;
            }
        }

        public void DefineDelegateRole(int roleID,int deliverType,List<int> delegates)
        {
            if(delegates !=null && delegates.Count > 0)
            {
                DAL.RemoveDelegatesByRole(roleID, deliverType); ;

                foreach (var delegateItem in delegates)
                {
                    DAL.AddDelegateWithRole(delegateItem, roleID, deliverType);
                }
            }
        }

        /// <summary>
        /// 根据权限获取业务类型
        /// </summary>
        /// <param name="roleID"></param>
        /// <param name="deliverType"></param>
        /// <returns></returns>
        public List<int> GetDelegatesByRoleID(int roleID, int deliverType)
        {
            return DAL.GetDelegatesByRoleID(roleID, deliverType);
        }
    }
}
